<?php

/**
 * This is the model class for table "{{banner_picture}}".
 *
 * The followings are the available columns in table '{{banner_picture}}':
 * @property integer $id
 * @property string $name
 * @property integer $size
 * @property string $ext
 * @property integer $banner_id
 * @property integer $create_time
 * @property integer $update_time
 *
 * The followings are the available model relations:
 * @property Banner $banner
 */
class BannerPicture extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return BannerPicture the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{banner_picture}}';
	}
	
    /**
     * @return array the behaviors to handle something
     */
    public function behaviors(){
        return array(
        	// Adds time stamp automatically
            'CTimestampBehavior' => array(
                'class' => 'zii.behaviors.CTimestampBehavior',
            ),
        );
    }

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, size, ext', 'required'),
			array('size, banner_id', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>16),
			array('ext', 'length', 'max'=>4),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('name, size, ext, banner_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'banner' => array(self::BELONGS_TO, 'Banner', 'banner_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'size' => 'Size',
			'ext' => 'Ext',
			'banner_id' => 'Banner',
			'create_time' => 'Create Time',
			'update_time' => 'Update Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('name',$this->name,true);
		$criteria->compare('size',$this->size);
		$criteria->compare('ext',$this->ext,true);
		$criteria->compare('banner_id',$this->banner_id);

		return new CActiveDataProvider($this, array(
			'pagination'=>array(
				'pageSize'=>Yii::app()->params['pageSize'],
			),
			'sort'=>array(
				'defaultOrder'=>'create_time DESC',
			),
			'criteria'=>$criteria,
		));
	}
}